package com.ruoyi.web.controller.shopping;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.shopping.domain.MallSwiper;
import com.ruoyi.shopping.service.IMallSwiperService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商城轮播图Controller
 *
 * @author ruoyi
 * @date 2022-06-17
 */
@RestController
@RequestMapping("/shopping/swiper")
public class MallSwiperController extends BaseController
{
    @Autowired
    private IMallSwiperService mallSwiperService;

    /**
     * 查询商城轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:swiper:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallSwiper mallSwiper)
    {
        startPage();
        List<MallSwiper> list = mallSwiperService.selectMallSwiperList(mallSwiper);
        return getDataTable(list);
    }

    /**
     * 导出商城轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:swiper:export')")
    @Log(title = "商城轮播图", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallSwiper mallSwiper)
    {
        List<MallSwiper> list = mallSwiperService.selectMallSwiperList(mallSwiper);
        ExcelUtil<MallSwiper> util = new ExcelUtil<MallSwiper>(MallSwiper.class);
        return util.exportExcel(list, "商城轮播图数据");
    }

    /**
     * 获取商城轮播图详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:swiper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallSwiperService.selectMallSwiperById(id));
    }

    /**
     * 新增商城轮播图
     */
    @PreAuthorize("@ss.hasPermi('shopping:swiper:add')")
    @Log(title = "商城轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallSwiper mallSwiper)
    {
        return toAjax(mallSwiperService.insertMallSwiper(mallSwiper));
    }

    /**
     * 修改商城轮播图
     */
    @PreAuthorize("@ss.hasPermi('shopping:swiper:edit')")
    @Log(title = "商城轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallSwiper mallSwiper)
    {
        mallSwiper.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(mallSwiperService.updateMallSwiper(mallSwiper));
    }

    /**
     * 删除商城轮播图
     */
    @PreAuthorize("@ss.hasPermi('shopping:swiper:remove')")
    @Log(title = "商城轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallSwiperService.logicDeleteMallSwiper(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
